<template>
	<view class="">
		<cu-custom bgColor="" :isBack="true">
			<view slot="backText">返回</view>
			<block slot="content">选择库位</block>
		</cu-custom>

		<view class="content">

			<view class="example-block">
				<view class="table">
					
					<z-table :textAlign="selectContent[nowType].textAlign" :titleTextAlign="selectContent[nowType].titleTextAlign"
					 :tableData="selectContent[nowType].tableData" :columns="selectContent[nowType].columns" @onSort="doSort"
					 :stickSide="selectContent[nowType].stickSide" :showBottomSum="selectContent[nowType].showBottomSum" :showLoading="false"
					 :emptyText='selectContent[nowType].emptyText' :tableHeight='selectContent[nowType].tableHeight' @onClick="rowClick"
					 :singleSelect="selectContent[nowType].singleSelect" :showSelect="selectContent[nowType].showSelect" @onSelect="tableSelect"></z-table>
				</view>
				<view class="" style="display: flex;justify-content: center;align-items: center;">
				
					<view>
						<button type="default" size="mini" :disabled="pre" @click="prePage">上一页</button>
					</view>
					<view style="float: right;">[{{pageNum}}/{{Math.ceil(total/pageSize)}}]</view>
					<view>
						<button type="default" size="mini" :disabled="next" @click="nextPage">下一页</button>
					</view>
				
					<view>共 {{total}} 条记录</view>
				
				</view>
				<view class="" style="display: flex;">
					<button class="select-btn" type="warn" @click="returnPage">返回</button>
					<button class="select-btn" type="primary" @click="selects">确认</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import zTable from "../../components/z-table/z-table.vue";
	import {
		request,
		ossUrl,
		getDictDataByDictType
	} from "../util/ajax.js";
	export default {
		data() {
			return {
				pageNum: 1,
				pageSize: 10,
				total: 1,
				nowType: 0,
				selectContent: [{
						textAlign: '', // 内容对齐方式
						titleTextAlign: '', // 表头对齐方式
						showLoading: true,
						tableData: [

						], // 表格数据
						columns: [{
								title: "库位类别",
								key: "storeTypeName",
							},
							{
								title: "库位名称",
								key: "storeLocationName",
							},
							{
								title: "库位面积",
								key: "storeLocationArea",
							},
						], // 表格列内容
						stickSide: true, // 左侧固定
						showBottomSum: false, // 底部显示统计
						emptyText: '无数据', // 表格内容为空时显示的内容
						tableHeight: 820, // 表格高度
						showSelect: true, // 开启选择功能
						formatNum:false,
						singleSelect:true
					},

				],
				index: '',
				selectList: [],
			}
		},
		components: {
			zTable
		},
		computed: {
			pre() {
				let self = this;
				if (self.pageNum == 1) {
					return true;
				}else{
					return false;
				}
			},
			next() {
				let self = this;
				if (self.pageNum == Math.ceil(self.total / self.pageSize)) {
					return true;
				}else{
					return false;
				}
			}
		},
		watch: {

		},
		onLoad(data) {
			this.index = data.index;
		},
		onShow() {
			this.getList();
		},
		methods: {
			selects() {
				let self = this;
				if (self.selectList.length < 1) {
					uni.showToast({
						icon: 'none',
						title: '请选择库位!'
					})
					return
				}
				const eventChannel = this.getOpenerEventChannel();

				let tableData = self.selectContent[0].tableData;
				let data = [];
				self.selectList.forEach(o => {
					data.push(tableData[o]);
				})
				eventChannel.emit('acceptDataFromStore',
					{data:data,index:self.index}
				);
				uni.navigateBack()
			},
			returnPage() {
				uni.navigateBack()
			},
			prePage(){
				this.pageNum--;
				this.getList();
			},
			nextPage(){
				this.pageNum++;
				this.getList();
			},
			getList() {
				let self = this;
				request({
					methods: "POST",
					url: "storehouse/selectStorehouseForInboundOrderLs",
					data: {
						pageNum:self.pageNum,
						pageSize:self.pageSize
					}
				}, 'query').then(res => {
					self.selectContent[0].tableData = res.data.rows;
						self.total=res.data.total;
				})
			},
			doSort(res) {
				uni.showToast({
					title: `点击了${res.key}的排序, 排序方式为${res.type}`,
					icon: "none"
				})
			},
			rowClick(item) {
				uni.showToast({
					title: `${JSON.stringify(item)}数据被点击`,
					icon: 'none'
				})
			},
			tableSelect(selectList) {
				console.log(selectList);
				this.selectList = selectList;
			}
		}
	};
</script>

<style lang="scss">
	.content {
		font-size: 24rpx;
	}



	.table {
		text-align: center;
	}
</style>
